#pragma once
#include "Edge.h"


bool Edge::operator ==(Edge &edge)
{
	if(&edge==NULL)
	{
		return false;
	}
	if(_vertexSet[0]==edge.getVertex(0)&&_vertexSet[1]==edge.getVertex(1))
	{
		return true;
	}
	else
	{
		return false;
	}
}

void Edge::deleteFace(int index)
{
	int nr_face=_faceSet.size();
	if(nr_face<1||index>=nr_face||index<0)
	{
		return;
	}
	_faceSet[index]=_faceSet[nr_face-1];
	_faceSet.pop_back();
}

void Edge::deleteFaceByValue(int value)
{
	for(int i=0;i<_faceSet.size();i++)
	{
		if(_faceSet[i]==value)
		{
			deleteFace(i);
			break;
		}
	}
}




int Edge::getFace(int index)
{
	if(index<_faceSet.size())
	{
		return _faceSet[index];
	}
	else 
	{
		return -1;
	}
}

bool Edge::hasFace(int index)
{
	for(int i=0;i<_faceSet.size();i++)
	{
		if(_faceSet[i]==index)
		{
			return true;
		}
	}
	return false;
}

int Edge::getAnotherVertex(int val)
{
	if(_vertexSet[0]==val)
	{
		return _vertexSet[1];
	}
	else if(_vertexSet[1]==val)
	{
		return _vertexSet[0];
	}
	return -1;
}

void Edge::clear()
{
	_faceSet.clear();
	_vertexSet.clear();
}


bool Edge::hasCommonVertex(Edge* other)
{
	for(int vertex_iterator1=0;vertex_iterator1<2;++vertex_iterator1) {
		int vertex_index1=this->getVertex(vertex_iterator1);
		for(int vertex_iterator2=0;vertex_iterator2<2;++vertex_iterator2) {
			int vertex_index2=other->getVertex(vertex_iterator2);
			if(vertex_index1==vertex_index2) {
				return true;
			}
		}
	}
	return false;
}